<?php

declare(strict_types=1);
namespace Service\MonitorService;

use Service\HttpServer\HttpCurl;
use Service\BaseService;

/**
 * 异常通知
 * @author chenshubo
 */
class MonitorService extends BaseService
{
    protected $url = 'https://oapi.dingtalk.com/robot/send?access_token=ead41db084b1ec8aaed4a478499b111a34fb2963160ff2f6343d63601211a7a6';
    /**
     * 发送系统异常
     * @param string $contents
     * @param string $AppName
     */
    public function sendMsg(string $contents,string $AppName='BBC搜索服务')
    {
        $server_ip = env('SERVER_IP');
        $service_ip = env('SERVICE_IP');
        $server_ip = $server_ip ? $server_ip : $service_ip;
        $message="【BBC商品消费异常】【{$AppName}-{$server_ip}】{$contents}";
        $data = [
            'msgtype' => 'text',
            'text' => [
                'content' => $message
            ]
        ];
        HttpCurl::instance()->apiRequest($this->url,$data,'POST','json',['Content-Type: application/json;charset=utf-8']);
    }
}